package cn.edu.scau.cmi.huhaoxian.adapterPattern.controller;

import java.util.ArrayList;

import cn.edu.scau.cmi.huhaoxian.adapterPattern.ITarget.Target;
import cn.edu.scau.cmi.huhaoxian.adapterPattern.adpater.ClassAdapter;
import cn.edu.scau.cmi.huhaoxian.adapterPattern.adpater.ObjectAdapter;
import cn.edu.scau.cmi.huhaoxian.adapterPattern.pojo.Student;
import cn.edu.scau.cmi.huhaoxian.factoryPattern.IFactory.Factory;
import cn.edu.scau.cmi.huhaoxian.factoryPattern.factory.BeefMeatFactory;
import cn.edu.scau.cmi.huhaoxian.factoryPattern.factory.ChickenMeatFactroy;
import cn.edu.scau.cmi.huhaoxian.factoryPattern.factory.PorkMeatFactory;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class InsertStudent {
	@FXML
    private Button class_adapte;
	@FXML
    private Button object_adapte;
	@FXML
	private TextField edite_name;
	@FXML
	private TextField edite_number;
	@FXML
    private TextArea text_info;
	
	private ArrayList<Student> students = new ArrayList<Student>();
	
    @FXML
    protected void handleClassButtonAction(ActionEvent event) {
    	text_info.setText(" ");
    	String nameString = edite_name.getText();
    	int number = Integer.parseInt(edite_number.getText());
    	students.add(new Student(number, nameString));
    	Target target = new ClassAdapter();
    	students = target.sortStudents(students);
    	for(Student student:students) {
    		text_info.appendText(student.toString());
    	}
    }
    
    @FXML
    protected void handleObjectButtonAction(ActionEvent event) {
    	text_info.setText(" ");
    	String nameString = edite_name.getText();
    	int number = Integer.parseInt(edite_number.getText());
    	students.add(new Student(number, nameString));
    	Target target = new ObjectAdapter();
    	students = target.sortStudents(students);
    	for(Student student:students) {
    		text_info.appendText(student.toString());
    	}
    }
}
